<template>
	<view class="">
		<!-- 顶部个人信息 -->
		<view class="bg-white">
			<view class="flex padding" v-if="!businessinfo || JSON.stringify(businessinfo) == '{}'">
				<view class="padding-lr-xs">
					<view class="cu-avatar lg round"
						style="background-image:url(https://image.meiye.art/Fha6tqRTIwHtlLW3xuZBJj8ZXSX3?imageMogr2/thumbnail/450x/interlace/1);">
					</view>
				</view>
				<view class="padding-xs text-xl text-black">
					<view
						style="font-size: 18px!important;margin-top: 6px;">请授权登录
					</view>
				
					<view class="cu-tag round line-green sm">已减排22.2g ></view>
				</view>
			</view>
			<view class="flex padding" v-else>
				<view class="padding-lr-xs" >
					<view class="cu-avatar lg round" style="margin:30px 20px">
						<u-image :showLoading="true" :src="businessinfo.userhead"  shape="circle" width="66px" height="66px" ></u-image>
					</view>
				</view>
				<view class="padding-xs text-xl text-black" >
					
					<view 
						style="font-size: 18px!important;margin-top: 26px;">{{ businessinfo.nickname }}
					</view>
					<view class="cu-tag round line-green sm">已减排22.2g ></view>
				</view>
			</view>
		</view>
		<!-- 基本数据 -->
		<view class="cu-list grid col-4 no-border padding-lr-xs radius-lg-bottom">
			<view class="cu-item">
				<view class="text-black text-bold text-xxl">
					6
				</view>
				<text>优惠券</text>
			</view>
			<view class="cu-item" @click="myrelease">
				<view class="text-black text-bold text-xxl">
					{{ relcount }}
				</view>
				<text>我的发布</text>
			</view>
			<view class="cu-item" @click="mysubject">
				<view class="text-black text-bold text-xxl">
					4
				</view>
				<text>我的课件</text>
			</view>
			<!-- <view class="cu-item">
				<view class="text-black text-bold text-xxl">
					4
				</view>
				<text>保修卡</text>
			</view> -->
			<view class="cu-item" @click="collection">
				<view class="text-black text-bold text-xxl">
					{{collectioncount}}
				</view>
				<text>我的收藏</text>
			</view>
		</view>
		<!-- 助力/推荐/邀请 -->
		<view class="margin-top-sm padding-lr-xs">
			<view class="bg-brown light radius-lg shadow-blur">
				<view class="flex padding-tb-sm padding-lr-sm justify-between">
					<view class="padding-xs">
						<view>9.9元开通超级会员最高可省￥40</view>
					</view>
					<view class="" @click="openlevel">
						<view class="cu-btn round bg-black">开通会员</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 常用功能 -->
		<view class="cu-bar margin-lr-xs margin-top-sm grid col-4 no-border bg-white radius-lg-top">
			<view class="action">
				<text class="text-xl text-black">我的订单</text>
			</view>
			<view class="action" @click="toAllOrder">
				<text class="text-lg">全部订单<text class="cuIcon-right"></text></text>
			</view>
		</view>
		<view class="cu-list grid col-4 no-border text-black margin-lr-xs padding-bottom radius-lg-bottom">
			<view class="cu-item" v-for="(item, index) in iconList" :key="index" :bindtap="item.bindtap">
				<view :class="['cuIcon-' + item.icon, 'text-' + item.color, 'text-shadow']" style="font-size: 56rpx;">
					<view class="cu-tag badge" v-if="item.badge != 0">
						<block v-if="item.badge != 1">{{ item.badge > 99 ? "99+" : item.badge }}</block>
					</view>
				</view>
				<text>{{ item.name }}</text>
			</view>
		</view>

		<view class="margin-top-sm padding-lr-xs">
			<view class="bg-white light radius-lg shadow-blur">
				<view class="flex padding-tb-sm padding-lr-sm justify-between">
					<view class="padding-xs">
						<view class="text-xl text-black">惊喜连连·洁净一秋</view>
						<view class="padding-top-xs">家居清洗限时<text class="text-red text-bold"> 6.6折 </text><text
								class="cuIcon-roundrightfill text-red"></text></view>
					</view>
					<view class="">
						<view class="cu-btn round bg-gradual-pinknew margin-top-sm">6折优惠</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 其他功能 -->
		<view class="cu-bar margin-lr-xs margin-top grid col-4 no-border bg-white radius-lg-top">
			<view class="action">
				<text class="text-xl">其他功能</text>
			</view>
		</view>
		<view class="cu-list grid col-4 no-border text-black margin-lr-sm padding-bottom radius-lg-bottom">
			<view class="cu-item" v-for="(item, index) in iconOtherList" :key="index" :bindtap="item.bindtap"
				@click="toItem(item)">
				<view :class="['cuIcon-' + item.icon, 'text-' + item.color, 'text-shadow']" style="font-size: 56rpx;">
					<view class="cu-tag badge" v-if="item.badge != 0">
						<block v-if="item.badge != 1">{{ item.badge > 99 ? "99+" : item.badge }}</block>
					</view>
				</view>
				<text>{{ item.name }}</text>
			</view>
			<view class="last">

				<button class="btnconcat" type="default" open-type="contact">


					<view :class="['cuIcon-' + 'mark', 'text-' + 'blue', 'text-shadow']"
						style="font-size: 56rpx;margin-top: -5px;"></view>

					<view class="text" style="margin-top: -10px;"> 在线咨询</view>


				</button>


			</view>
		</view>

		<view>

			<!-- <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" withCredentials="true">获取手机号</button> -->
			<button open-type="getPhoneNumber" type="primary" @getuserinfo="user" @getphonenumber="getPhoneNumber"
				withCredentials="true">微信一键授权</button>
			<!-- <button @click="login">授权</button> -->


		</view>


		<u-toast ref="notice"></u-toast>



	</view>
</template>

<script>

export default {


	data() {
		return {
			collectioncount:0,
			relcount:0,
			businessinfo: {},
			iconList: [{
				icon: 'moneybagfill',
				color: 'blue',
				badge: 0,
				name: '待接单'
			}, {
				icon: 'presentfill',
				color: 'red',
				badge: 0,
				name: '待上门',
				bindtap: "bindZan"
			}, {
				icon: 'formfill',
				color: 'purple',
				badge: 11,
				name: '待评价',
				bindtap: "showResource"
			}, {
				icon: 'shopfill',
				color: 'green',
				badge: 0,
				name: '返修/售后',
				bindtap: "bindPoint"
			}],
			iconOtherList: [{
				icon: 'location',
				color: 'blue',
				badge: 0,
				cur: 1,
				name: '地址管理',
			}, {
				icon: 'service',
				cur: 2,
				color: 'blue',
				badge: 0,
				name: '电话客服',
				bindtap: "bindZan"
			}, {
				icon: 'mail',
				color: 'blue',
				cur: 4,
				badge: 0,
				name: '投诉',
				bindtap: "bindCollect"
			}, {
				icon: 'settings',
				color: 'blue',
				cur: 5,
				badge: 0,
				name: '设置',
				bindtap: "bindZan"
			}],
			companyphone: ""
		}
	},

	onLoad() {

		this.businessinfo =this.$u.business.check()


		this.getcompanymobile()
	},
	onShow()
	{
		this.myreleasecount()
		this.mycollection()

	},
	methods: {

		// 我的收藏
		collection()
		{
			uni.$u.route({
				url:"pagesA/product/collection"
			})
			
			
		},

		toAllOrder()
		{
			uni.$u.route({
				url:"pagesC/order/order"
			})
		},
		async myreleasecount()
		{
			let data = {
				busid:this.businessinfo.id
			}
			let result = await this.$u.api.product.releasecount(data)
			if(result.code)
			{
				this.relcount = result.data
			}
		},
		async mycollection()
		{
			let data = {
				busid:this.businessinfo.id
			}
			let result = await this.$u.api.product.collectiontotal(data)
			if(result.code)
			{
				this.collectioncount = result.data
			}
		},

		myrelease()
		{

			uni.$u.route({
				url:"pagesC/releaseCar/releaseRecords",
				params:{
					busid:this.businessinfo.id
				}
			})
		},
		openlevel() {
			uni.$u.route({
				url: "pagesB/server/server2"
			})
		},
		toItem(e) {
			if (e.cur == 1) {
				uni.$u.route({
					url: "pagesB/address/index"
				})
			} else if (e.cur == 2) {
				this.bodaphone()
			} else if (e.cur == 3) {


			}else if(e.cur == 5)
			{
				uni.$u.route({
					url:"pages/index/setting"
				})
			}


		},

		// 获取手机号包含了弹出授权的东西
		getPhoneNumber(mobile) {

			let that = this
			if (mobile.detail.errMsg.trim() == "getPhoneNumber:ok") {
				// 调用 uni.showModal() 或者 uni.showPopup() 方法弹出层来提示用户进行手机号授权操作
				uni.showModal({
					title: '获取手机号授权',
					content: '请授权获取手机号',
					success: function (res) {
						if (res.confirm) {

							//调用微信小程序的授权登录接口

							uni.getUserProfile({
								desc: '获取你的昵称、头像、地区及性别',
								fail: () => {
									this.$refs.notice.show({
										type: 'error',
										message: '您拒绝了授权'
									})
								},
								success: (info) => {
								


								

									uni.login({
										provider: 'weixin',
										success: async (result) => {
											

											uni.request({
												url: uni.getStorageSync('URL') + 'home/user/user/login',
												method: 'POST',
												data: {
													logincode: result.code,
													phonecode: mobile.detail.code,
													encryptedDataStr: mobile.detail.encryptedData,
													iv: mobile.detail.iv,
													avatar:info.userInfo.avatarUrl,
													nickname:info.userInfo.nickName
												},
												header: {
													"X-Requested-With": "XMLHttpRequest"
												},
												dataType: 'json',
												success: (res) => {
													console.log(res.data.data)

													that.businessinfo = res.data.data
													console.log(that.businessinfo)

													//保存登录的信息
													uni.setStorageSync('userinfo',res.data.data)

													that.$refs.notice.show({
														type: 'success',
														message: '授权登录成功',
														duration: 2000,
													})

												},
												fail: (res) => {
													that.$refs.notice.show({
														type: 'danger',
														message: '授权登录失败',
														duration: 2000,
													})
												}

											});







										},
										fail: () => {
											this.$refs.notice.show({
												type: 'error',
												message: '授权登录临时凭证获取失败'
											})
										}
									})
								}
							})
							// console.log(e)
						} else {
							// 用户点击取消按钮
							// 处理取消获取手机号的情况
							this.$refs.notice.show({
								type: "success",
								message: "已取消获取手机号"
							})
						}
					}
				});

			}




		},

		noticeSwitch() {
				const SUBSCRIBE_ID = 'jzU68L4qvLiXHjp0eUMmPJmTPe0ZoOxzSLMt7pAArSs' // 模板ID
				let that = this;
				uni.requestSubscribeMessage({
					//此处填写刚才申请模板的模板ID
					tmplIds: [SUBSCRIBE_ID],
					success (res) {
						let result = res[SUBSCRIBE_ID]
						if (result === 'accept') {
							that.checked = true
							wx.showToast({
							  title: '订阅消息提示成功',
							  icon: 'none'
							})
						} else if (result === 'reject') {
							that.checked = false
							wx.showToast({
							  title: '订阅消息提示失败',
							  icon: 'none'
							})
						}						
					}
				})
				
			},

		// 奢总汇电话客服
		async getcompanymobile() {
			let result = await this.$u.api.user.companyphone()
			{
				if (result.code) {
					this.companyphone = result.data
				}
			}
		},

		bodaphone() {
			uni.makePhoneCall({
				phoneNumber: this.companyphone, //仅为示例
				success: () => {
					console.log("拨打成功")
				}
			});

		},
		mysubject()
		{
			uni.$u.route({
				url:"pagesD/douyin/index"
			})
		}





	}


}
</script>

<style lang="scss">
/*每个页面公共css */
@import "../../static/colorui/main.css";
@import "../../static/colorui/icon.css";

.last {
	padding: -45px -15px;


	.btnconcat {
		width: 100px;
		text-align: center;
		font-size: 13px;
		height: 95px !important;
		position: relative;
		border: none;
		color: #888 !important;
		margin-left: -10px;

		background: #ffffff !important;

		.text {
			position: absolute;
			left: 25%;
			top: 59%;
			color: #888;
		}


	}

}







.btnconcat::after {

	border: none;
}

.getnickbox {
	padding: 40rpx 20rpx;

	.flex_align_center {
		display: flex;

		.logoimg {
			width: 50rpx;
			height: 50rpx;
		}

		.name {
			margin-left: 20rpx;

			text {
				margin-left: 10rpx;
			}
		}
	}

	.m1 {
		font-weight: 500;
	}

	.m2 {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid #f2f2f2;
		color: #999;
		padding-top: 10rpx;
		font-size: 24rpx;
	}

	.xin1 {
		border-bottom: 1rpx solid #f2f2f2;
		margin-bottom: 30rpx;

		.toubox {
			padding: 10rpx 0;
			display: flex;

			.t1 {
				font-size: 28rpx;
				margin-right: 30rpx;
				margin-top: 11rpx;
			}

			.avatarbox {
				width: 100rpx;
				height: 100rpx;
				border-radius: 20rpx;
			}

			.avatarimg {
				width: 100rpx;
				height: 100rpx;
				border-radius: 20rpx;
			}
		}
	}

	.buttoncss {
		background-color: #fff;
		border-radius: 0px;
		border: 0rpx solid transparent;
		display: flex;
	}

	button::after {
		border: 0px solid rgba(0, 0, 0, .2);
	}

	.nick {
		padding-bottom: 30rpx;
		border-bottom: 2rpx solid #f2f2f2;
		display: flex;
		align-items: center;
		padding-left: 14px;
		padding-right: 14px;

		.n1 {
			font-size: 28rpx;
			margin-right: 30rpx;
		}
	}

	.wan {
		position: relative;
		height: 100rpx;
		box-shadow: 0rpx 0rpx 0rpx 0rpx;
		margin-top: 30rpx;
	}

	.mt30 {
		margin-top: 30rpx;
	}
}

.loginvalue {
	width: 750rpx;
	height: 450rpx;
	background-color: #fff;

	.logotitle {
		width: 84%;
		padding: 30rpx 8% 0rpx 8%;
		height: 100rpx;
		display: flex;
		justify-content: flex-start;

		.logo {
			width: 50rpx;
			height: 50rpx;
			line-height: 130rpx;
		}

		.title {
			line-height: 100upx;
			height: 100upx;
			font-weight: 500upx;
			margin-left: 10rpx;
		}
	}

	.titlename {
		width: 84%;
		height: 100rpx;
		padding: 0upx 8%;
		line-height: 100rpx;
		font-weight: 600rpx;
	}

	.titlemin {
		width: 84%;
		padding: 0rpx 8%;
		height: 100rpx;
		line-height: 10rpx;
	}

	.submitbox {
		padding: 0rpx 8%;
		height: 80rpx;
		line-height: 80rpx;
		display: flex;
		justify-content: center;

		.close {
			width: 200rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 10rpx;
			margin-right: 40rpx;
		}

		.open {
			width: 200rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 10rpx;
			margin-left: 40rpx;
			position: relative;

			button::after {
				height: 80rpx;
				line-height: 80rpx;
				border: 1rpx solid rgba($color: #000000, $alpha: 0);
				text-align: center;
				width: 200rpx;
				padding: 0rpx;
			}

			button {
				position: absolute;
				top: 0rpx;
				left: 0rpx;
				height: 80rpx;
				line-height: 80rpx;
				border: 1rpx solid rgba($color: #000000, $alpha: 0);
				text-align: center;
				width: 200rpx;
				padding: 0rpx;
			}
		}
	}
}

.loginvalue {
	width: 750rpx;
	height: 450rpx;
	background-color: #fff;

	.logotitle {
		width: 84%;
		padding: 30rpx 8% 0rpx 8%;
		height: 100rpx;
		display: flex;
		justify-content: flex-start;

		.logo {
			width: 50rpx;
			height: 50rpx;
			line-height: 130rpx;
		}

		.title {
			line-height: 100upx;
			height: 100upx;
			font-weight: 500upx;
			margin-left: 10rpx;
		}
	}

	.titlename {
		width: 84%;
		height: 100rpx;
		padding: 0upx 8%;
		line-height: 100rpx;
		font-weight: 600rpx;
	}

	.titlemin {
		width: 84%;
		padding: 0rpx 8%;
		height: 100rpx;
		line-height: 10rpx;
	}

	.submitbox {
		padding: 0rpx 8%;
		height: 80rpx;
		line-height: 80rpx;
		display: flex;
		justify-content: center;

		.close {
			width: 200rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 10rpx;
			margin-right: 40rpx;
		}

		.open {
			width: 200rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 10rpx;
			margin-left: 40rpx;
			position: relative;

			button::after {
				height: 80rpx;
				line-height: 80rpx;
				border: 1rpx solid rgba($color: #000000, $alpha: 0);
				text-align: center;
				width: 200rpx;
				padding: 0rpx;
			}

			button {
				position: absolute;
				top: 0rpx;
				left: 0rpx;
				height: 80rpx;
				line-height: 80rpx;
				border: 1rpx solid rgba($color: #000000, $alpha: 0);
				text-align: center;
				width: 200rpx;
				padding: 0rpx;
			}
		}
	}
}
</style>
